package cn.sirun.com.fca.map.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tencent.lbssearch.object.result.SuggestionResultObject;

import java.util.List;

import cn.sirun.com.fca.map.R;
import cn.sirun.com.fca.map.listener.MyItemLongClickListener;
import cn.sirun.com.fca.map.model.SearchResultData;

/**
 * Descrip:
 * Author: Administrator
 * Time: 2018/11/27
 * Version:
 */

public class SearchResultAdapter extends RecyclerView.Adapter<SearchResultAdapter.ViewHolder> {

    private List<SuggestionResultObject.SuggestionData> mSuggestionDatas;
    private LayoutInflater inflater;
    private Context mContext;
    private MyItemLongClickListener listener;
    public void setListener(MyItemLongClickListener listener) {
        this.listener = listener;
    }
    public SearchResultAdapter(List<SuggestionResultObject.SuggestionData> mSuggestionDatas, Context context) {
        this.mSuggestionDatas = mSuggestionDatas;
        this.mContext = context;
        this.inflater = LayoutInflater.from(context);
    }
    public List<SuggestionResultObject.SuggestionData> getCarStatusData(){
        return mSuggestionDatas;
    }
    public void setCarStatusData(List<SuggestionResultObject.SuggestionData> searchResultData) {
        this.mSuggestionDatas = searchResultData;
    }
    @Override
    public SearchResultAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.map_search_result_items,null,false);

        return new ViewHolder(view);
    }
    @Override
    public void onBindViewHolder(SearchResultAdapter.ViewHolder holder, final int position) {
        SuggestionResultObject.SuggestionData crd = mSuggestionDatas.get(position);
        holder.map_address.setText(crd.title);
        holder.map_line.setText(crd.address);

        if (listener != null) {
            holder.rootView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.onItemLongClick(v, position);
                }
            });
        }
    }
    @Override
    public int getItemCount() {
        return mSuggestionDatas == null ? 0 : mSuggestionDatas.size();
    }
    public static class ViewHolder extends RecyclerView.ViewHolder {
        public View rootView;
        public TextView map_address;//数据参数
        public TextView map_line;//参数值

        public ViewHolder(View rootView) {
            super(rootView);
            this.rootView = rootView;
            this.map_address = (TextView) rootView.findViewById(R.id
                    .tv_map_result_address);
            this.map_line = (TextView) rootView.findViewById(R.id
                    .tv_map_result_line);
        }

    }

}
